import Vue from 'vue'
import App from './App.vue'
import router from './router'

import store from './vuex/store'
// 引入element-ui组件库
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/css/global.css'
//引入树形结构
import TreeTable from 'vue-table-with-tree-grid'
// 引入阿里图标库
import './assets/fonts/iconfont.css'
// 进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 配置基准路径
import axios from 'axios'

axios.defaults.baseURL = `http://127.0.0.1:8888/api/private/v1/`
Vue.prototype.$http = axios
// 设置请求拦截器
axios.interceptors.request.use(config => {
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// 响应拦截器
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.component('tree-table', TreeTable)
//添加一个全局的时间过滤器
Vue.filter('dateFormate', function (originVal) {
  let time = new Date(originVal)
  let y = time.getFullYear()
  let m = (time.getMonth() + 1 + '').padStart(2, '0')
  let d = (time.getDate() + '').padStart(2, '0')
  let h = (time.getHours() + '').padStart(2, '0')
  let min = (time.getMinutes() + '').padStart(2, '0')
  let s = (time.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${h}:${min}:${s}`
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
